package com.letsgo;

import java.util.ArrayList;
import java.util.Date;

public class RequesterTest implements Requester {

	@Override
	public void createGame(Game g) throws RequesterUnauthorizedException,
			RequesterUnsupportedMediaTypeException {
		

	}

	@Override
	public void createUser(Player p) throws RequesterMissingPwdException {
		

	}

	@Override
	public void deleteGame(Game g) throws RequesterUnauthorizedException,
			RequesterForbiddenException, RequesterNotFoundException {
		

	}

	@Override
	public void inviteUser(Game g) throws RequesterUnauthorizedException,
			RequesterNotFoundException, RequesterUnsupportedMediaTypeException {
		

	}

	@Override
	public void joinGame(Game g) throws RequesterUnauthorizedException,
			RequesterNotFoundException, RequesterUnsupportedMediaTypeException {
		

	}

	@Override
	public ArrayList<Game> listGames(int start, int end, boolean last) {
		Player g = new Player("Guillem SAINT-GERMES", "gsg", null);
		Player r = new Player("Robin LEHAUT", "rl", null);
		Player t = new Player("Julien Tagneres", "jt", null);
		ArrayList<Game> res = new ArrayList<Game>();
		Game garray[] = null ;
		try{
			Game[] garray2 = {
			
				new Game(1, new Date(2011, 2, 20), g, r, GAME_STATUS.FULL, true, null),
				new Game(8, new Date(2011, 2, 22), g, t, GAME_STATUS.FULL, true, null),
				new Game(2, new Date(2011, 1, 28), r, null, GAME_STATUS.OPEN, true, null),
				new Game(3, new Date(2011, 1, 28), r, t, GAME_STATUS.FULL, true, null),
				new Game(6, new Date(2011, 1, 15), t, r, GAME_STATUS.CLOSED, true, null),
				new Game(4, new Date(2010, 1, 30), r, null, GAME_STATUS.OPEN, true, null),
				new Game(5, new Date(2011, 1, 28), t, null, GAME_STATUS.OPEN, true, null),
				new Game(7, new Date(2011, 1, 12), t, g, GAME_STATUS.CLOSED, true, null)
			};
			garray = garray2 ;
		}catch(Exception e) {
			return res;
		}
		
		for(Game game : garray)
		{
			if(!game.getStatus().equals(GAME_STATUS.CLOSED))
			{
				res.add(game);
			}
		}
		
		return res;
	}

	@Override
	public ArrayList<Player> listUsers(int start, int end, boolean last) {
		Player g = new Player("Guillem SAINT-GERMES", "gsg", null);
		Player r = new Player("Robin LEHAUT", "rl", null);
		Player t = new Player("Julien Tagneres", "jt", null);
		
		ArrayList<Player> res = new ArrayList<Player>();
		res.add(g);
		res.add(r);
		res.add(t);
		
		return res;
	}

	@Override
	public ArrayList<BoardMovement> moveHistory(Game g, int start, int end,
			boolean last) throws RequesterNotFoundException {
		ArrayList<BoardMovement> res = new ArrayList<BoardMovement>();
		
		if(end < start || g == null )
			return res ;
		
		int size[] = g.getSize();
		int count = 1 ;
		int c = 0 ;
		int r = 0 ;
		for(int i=start ; i<end ; i++)
		{
			if(c >= size[0])
			{
				c=0 ;
				r++ ;
			}
			res.add(new BoardMovement(count, r, c));
			c++;
			count++;
		}
		return res;
	}

	@Override
	public void playMove(Game g, BoardMovement b)
			throws RequesterUnauthorizedException, RequesterForbiddenException,
			RequesterNotFoundException {
		

	}

	@Override
	public Game retrieveGame(Game g) throws RequesterNotFoundException {
		Board b = new Board(19,19);
		g.setGameBoard(b);

		ArrayList<BoardMovement> bms = moveHistory(g,0,10, false);
		
		try {
			b.fillFromHistory(bms);
		} catch (BoardBadHistory e) {
			
		}
		
		g.setGameBoard(b);
		
		return g;
	}

	@Override
	public Player getOwner() {
		// TODO Auto-generated method stub
		return null;
	}

	@Override
	public void setOwner(Player p) {
		// TODO Auto-generated method stub
		
	}

}
